use diesel::prelude::*;
use dotenvy::dotenv;
use std::env;
use anyhow::Result;

pub fn establish_connection() -> Result<PgConnection> {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
    let connection = PgConnection::establish(&database_url)?;
    Ok(connection)
}